
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/26/2010 16:11:18
-- Generated from EDMX file: C:\Data\Projects\OrienteeringMaps\DataAccess\OrienteeringMapsDB.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [OrienteeringMaps];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Clubs'
CREATE TABLE [dbo].[Clubs] (
    [ID] uniqueidentifier  NOT NULL,
    [Name] varchar(50)  NOT NULL
);
GO

-- Creating table 'Maps'
CREATE TABLE [dbo].[Maps] (
    [ID] uniqueidentifier  NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [Number] varchar(10)  NULL,
    [ReleaseYear] int  NOT NULL,
    [Club_ID] uniqueidentifier  NOT NULL,
    [Scale_ID] uniqueidentifier  NOT NULL,
    [PointOfSale_ID] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'PointsOfSale'
CREATE TABLE [dbo].[PointsOfSale] (
    [ID] uniqueidentifier  NOT NULL,
    [Contact] varchar(50)  NULL,
    [Adress] varchar(50)  NULL,
    [PLZ] int  NULL,
    [City] varchar(50)  NULL,
    [Country] varchar(50)  NULL,
    [Telephone] varchar(50)  NULL,
    [EMail] varchar(50)  NULL
);
GO

-- Creating table 'MapScales'
CREATE TABLE [dbo].[MapScales] (
    [ID] uniqueidentifier  NOT NULL,
    [Scale] int  NOT NULL,
    [ScaleText] nvarchar(50)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Clubs'
ALTER TABLE [dbo].[Clubs]
ADD CONSTRAINT [PK_Clubs]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Maps'
ALTER TABLE [dbo].[Maps]
ADD CONSTRAINT [PK_Maps]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'PointsOfSale'
ALTER TABLE [dbo].[PointsOfSale]
ADD CONSTRAINT [PK_PointsOfSale]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'MapScales'
ALTER TABLE [dbo].[MapScales]
ADD CONSTRAINT [PK_MapScales]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Club_ID] in table 'Maps'
ALTER TABLE [dbo].[Maps]
ADD CONSTRAINT [FK_Maps_Club]
    FOREIGN KEY ([Club_ID])
    REFERENCES [dbo].[Clubs]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Maps_Club'
CREATE INDEX [IX_FK_Maps_Club]
ON [dbo].[Maps]
    ([Club_ID]);
GO

-- Creating foreign key on [Scale_ID] in table 'Maps'
ALTER TABLE [dbo].[Maps]
ADD CONSTRAINT [FK_Maps_Maps]
    FOREIGN KEY ([Scale_ID])
    REFERENCES [dbo].[MapScales]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Maps_Maps'
CREATE INDEX [IX_FK_Maps_Maps]
ON [dbo].[Maps]
    ([Scale_ID]);
GO

-- Creating foreign key on [PointOfSale_ID] in table 'Maps'
ALTER TABLE [dbo].[Maps]
ADD CONSTRAINT [FK_Maps_PointOfSale]
    FOREIGN KEY ([PointOfSale_ID])
    REFERENCES [dbo].[PointsOfSale]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Maps_PointOfSale'
CREATE INDEX [IX_FK_Maps_PointOfSale]
ON [dbo].[Maps]
    ([PointOfSale_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------